﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common
{
   
    public enum ErrorInfo
    {
        Succeed,
        Err_Bad_Request_Information,//请求不匹配，如请求ID与资源ID号不一致
        Err_Resource_Sealed, //资源已经封存，如已经完成装托
        Err_Resource_Occupied, //资源已经被占用（比如已经装托过程中）
        Err_Resource_Deleted,//资源已经被删除（逻辑删除）
        Err_Resource_Exeed,//超出资源容限
        Err_Resource_NotMatch,//资源不匹配，如Item不相符
        Err_Resource_Exist,//资源已存在
        Err_Resource_NotExist,//资源不存在
        Err_Internal_Error //内部错误，原因不明
    }
    public enum ResourceStatus
    {
        Normal,//正常可用
        Occupied,//已被占用
        Sealed //已经关闭
    }
    public enum ActionMethod
    {
        
        Write ,
        Read ,
        Visible ,
        None
    }
    public enum HttpMethod
    {
        None,
        Get,
        Post
    }
    public enum ActionType
    {
        WebMenu,
        NoneWebMenu,
        DataBase,
        WinForm
    }
    public static class SettingItems
    {
        public static string userDbConnStr = "ConnectionString.UserDB";
        public static string shippingDbConnStr = "ConnectionString.shippingDB";
        public static string rememberUser = "rememberUser";
        public static string bgBanzuMode = "BanzuMode";
    }

   
    public class OleSource
    {
        public string fileName;
        public string userID;
        public string password;
        public bool header = true;
        public eFileMode fileMode = eFileMode.Read;

        public string ConnectString { get
            {
                string hdr = header ? "Yes" : "No";
                string mConnectionString = "";
                string extName = fileName.Substring(fileName.LastIndexOf("."));
                if (extName.ToUpper() == ".MDB")
                {

                    mConnectionString = " Provider = Microsoft.Jet.OleDb.4.0; Data Source=" + fileName;
                }
                else if (extName.ToUpper() == ".ACCDB")
                {
                    mConnectionString = " Provider = Microsoft.ACE.OLEDB.12.0; Data Source=" + fileName;
                }
                else if (extName.ToUpper() == ".XLSB" || extName.ToUpper() == ".XLSX")
                {
                    mConnectionString = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source = " + fileName
                    + "; Extended Properties = 'Excel 12.0;";
                }
                else
                {
                    mConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " + fileName
                    + "; Extended Properties = 'Excel 8.0;";
                }
                mConnectionString += " HDR=" + hdr + ";IMEX=" + (int)fileMode + ";'";
                /*  Excel 12.0用于EXCEL2007以上版本，8.0 针对Excel2000及以上版本，Excel5.0 针对Excel97。
                    HDR = Yes 表示第一行包含列名,在计算行数时就不包含第一行
                    IMEX   0:写入模式,1:读取模式: 2读写模式 */
                if (string.IsNullOrEmpty(password))
                {

                    mConnectionString += ";Persist Security Info=False;";
                }
                else
                {//"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+oleSource.fileName+";Persist Security Info=True";
                    mConnectionString += ";Persist Security Info=True;User ID='" + userID + "';Password='" + password + "'";
                }
                return mConnectionString;
            } }
    }
    //读写模式,0:写入模式,1:读取模式: 2读写模式
    public enum eFileMode { Write, Read, ReadAndWrite }
}
